<template>

	<view class="cu-list menu" :class="['sm-border','card-menu margin-top']">
		<!-- <view class="cu-item arrow" @tap="edit(i18n.set.head, 'avatar','',3)"> -->
		<view class="cu-item arrow">
			<image class="cu-avatar round " :src="userinfo.avatar" mode=""></image>
			<view class="content">
			</view>
			<view class="action">
				<text class="text-grey">{{i18n.set.head}}</text>
			</view>
		</view>
		<!-- <view class="cu-item" v-if="userinfo.mobile !== ''">
			<view class="content">
				<text class="text-grey">{{i18n.set.mobile}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{userinfo.mobile}}</text>
			</view>
		</view> -->
		<view class="cu-item arrow" @tap="edit(i18n.set.bindmobile, 'mobile',userinfo.mobile,6)" v-if="userinfo.mobile == ''">
			<view class="content">
				<text class="text-grey">{{i18n.set.mobile}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{i18n.set.unbind}}</text>
			</view>
		</view>
		<view class="cu-item" v-if="userinfo.email !== ''">
			<view class="content">
				<text class="text-grey">{{i18n.set.email}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{userinfo.email}}</text>
			</view>
		</view>
		<view class="cu-item arrow" @tap="edit(i18n.set.bindemail, 'email',userinfo.email,7)" v-if="userinfo.email == ''">
			<view class="content">
				<text class="text-grey">{{i18n.set.email}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{i18n.set.unbind}}</text>
			</view>
		</view>

		<view class="cu-item arrow" @tap="edit(i18n.set.nickname, 'nickname',userinfo.nickname,1)">
			<view class="content">
				<text class="text-grey">{{i18n.set.nickname}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{userinfo.nickname}}</text>
			</view>
		</view>
		<view class="cu-item arrow" @tap="edit(i18n.set.resetpassword, 'password','',5,0)">
			<view class="content">

				<text class="text-grey">{{i18n.set.password}}</text>
			</view>
		</view>
		<view class="cu-item arrow" @tap="edit(i18n.set.resetpassword2, 'password2','',2,0)">
			<view class="content">

				<text class="text-grey">{{i18n.set.paypassword}}</text>
			</view>
		</view>
		<!-- <view class="cu-item arrow" @tap="edit('imtoken', 'imtoken',userinfo.imtoken,4)">
			<view class="content">

				<text class="text-grey">imtoken</text>
			</view>
		</view> -->
		<view class="cu-item arrow" @tap="navTo('/pages/address2/address')">
			<view class="content">

				<text class="text-grey">{{i18n.set.payment}}</text>
			</view>
		</view>
		<view class="cu-item arrow" @tap="navTo('/pages/set/google')" v-if="userinfo.is_b  == 0">
			<view class="content">
				<text class="text-grey">{{i18n.set.google}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{i18n.set.unbind}}</text>
			</view>
		</view>
		<view class="cu-item  " v-if="userinfo.is_b  == 1" >
			<view class="content">
				<text class="text-grey">{{i18n.set.google}}</text>
			</view>
			<view class="action">
				<text class="text-grey">{{i18n.set.bind}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState
	} from 'vuex';
	// import prompt from './child/prompt'
	export default {
		// components: {
		// 	prompt
		// },
		data() {
			return {
				title: '',
				key: '',
			};
		},
		computed: {
			...mapState({
				userinfo: state => state.user.userinfo
			}),
			i18n() {
				return this.$t('message');
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.i18n.set.set
			});
		},
		methods: {
			...mapMutations(['SAVE_USERINFO']),
			edit(title, key, value, type, needcode = 0) {
				let form = {
					type: type,
					needcode: needcode,
					nickname: '',
					avatar: '',
					// mobile: this.userinfo.mobile,
					code: '',
					password2: '',
					imtoken: '',
				}
				form[key] = value;
				uni.navigateTo({
					url: `/pages/set/form?data=${JSON.stringify(form)}` + `&title=` + title
				})
			},
			// submit(val) {
			// 	let form = {}
			// 	form[this.key] = val
			// 	this.$http.post('user.info.edit', form).then(res => {
			// 		this.$refs.$prop.close()
			// 		uni.showToast({
			// 			title: '修改成功'
			// 		})
			// 		this.SAVE_USERINFO(res.data)
			// 	})
			// },
			navTo(url) {
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style lang='scss'>
	page {
		background: $page-color-base;
	}
</style>
